/*
 * Copyright (c) 2025, 廖树财, <study_2030@163.com>
 *
 * PEE2.0-YCYW-HY is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *         http://license.coscl.org.cn/MulanPSL2     
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */
#ifndef _IOTA_IMP_H_
#define _IOTA_IMP_H_
#include "define.h"
#include "iota.h"
#include "JsonParser.h"

#include "mqtt/MQTTAsync.h"


#include "common.h"

#define IOTA_BUF_SIZE_64 64
#define IOTA_BUF_SIZE_128 128
#define IOTA_BUF_SIZE_256 256
#define IOTA_BUF_SIZE_512 512
#define IOTA_BUF_SIZE_1K 1024

extern char *CLIENT_SIGN_CERT_PATH;
extern char *CLIENT_SIGN_KEY_PATH;
extern char *CLIENT_ENC_CERT_PATH;
extern char *CLIENT_ENC_KEY_PATH;
extern char *CLIENT_CA_CERT_PATH;

extern char* CLIENT_CA_CERT_PATH_V1;
extern char* CLIENT_SIGN_CERT_PATH_V1;
extern char* CLIENT_SIGN_KEY_PATH_V1;


void IOTA_setCallbackSag(PFN_CALLBACK_HANDLER_SAG pfnCallbackHandler);
int IOTA_sendMqtt(char *pcTopicName, char *buf, int size);
int IOTA_sendToLocalMqtt(char *pcTopicName, char *buf);
///

int IOTA_init(char *pcWorkPath, char *pcLogPath);
void IOTA_destroy();

void IOTA_setCallbackWithTopic(PFN_CALLBACK_HANDLER_TOPIC pfnCallbackTopicHandler);
void IOTA_setPrintLogCallback(PFN_LOG_CALLBACK_HANDLER pfnLogCallbackHandler);

int IOTA_configSetStr(int iItem, char *pValue);
int IOTA_configSetUint(int iItem, HW_UINT uiValue);

int IOTA_login();
int IOTA_login_fromiplist();
int IOTA_login_frommqttconf();
int IOTA_logout();

int IOTA_hubDeviceAdd(HW_UINT uiMid, ST_IOTA_DEVICE_INFO *pstInfo);
int IOTA_hubDeviceRemove(HW_UINT uiMid, char *pcDeviceId);
int IOTA_deviceStatusUpdate(HW_UINT uiMid, char *pcDeviceId, char *pcStatus);
int IOTA_hubDeviceQuery(HW_UINT uiMid, char *pcMarker, HW_UINT uiLimit, ST_IOTA_DEVICE_INFO *pstDeviceInfo);

int IOTA_serviceDataReport(char *pcDeviceId, char *pcServiceId, char *pcServiceProperties);
int IOTA_serviceCommandResponse(HW_UINT uiMid, HW_UINT uiResultCode, char *pcCommandResponse);

int IOTA_serviceCustomTopicReport(ST_IOTA_BatchReportProperties *pstDevInfo, char *pcTopicVersion, char *pcCustomTopic);
int IOTA_subscribeCustomTopic(char *pcTopicVersion, char *pcCustomTopic);

int IOTA_setCertPath(char *pcCertPath);

void getUrl(char *pcUrl);

void getUrl_v1(char* ip, char* pcUrl, int tailor);
void getUrlV2(char* ip, char* pcUrl, uint16_t iPort);
void getUrl_v3(char* ip, char* pcUrl, char* tailor);

int publishMessage(char *pcTopicName, char *pcMessage);

// typedef int (*fun_handle)(char* ,int);
// void setCallbackSecurity(fun_handle pFun);
// void setCallbackmengbo(fun_recv pFun);
// void setCallbacklishuaimin(fun_recv pFun);

// HW_BOOL device_proc(char* pcJson, unsigned int* uiMid, int* iStatusCode, char* pcStatusDecs);

// HW_BOOL log_proc(char* pcJson, unsigned int* uiMid, int* iStatusCode, char* pcStatusDecs);

// HW_BOOL security_proc(char* pcJson, unsigned int* uiMid, int* iStatusCode, char* pcStatusDecs);

#endif // _IOTA_IMP_H_
